package com.foruo.sc.upload.file.server;

import com.foruo.sc.upload.file.server.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;

/**
 * 文件资源服务
 * @author GaoYuan
 * @date 2018/4/10 下午3:20
 */
@Controller
@RequestMapping("/file")
@EnableAutoConfiguration
public class DeleteFileServerController {

    @Autowired
    UploadFileService uploadFileService;

    //获取配置文件中图片的路径
    @Value("${raising.upload.imagesPath}")
    private String mImagesPath;
    /**
     * 上传文件
     * @author GaoYuan
     * @date 2018/4/10 上午10:10
     */
    @PostMapping(value="/delete")
    @ResponseBody
    public String delete(String url) {
        try{
            File file = new File(mImagesPath + url);
            if(file.exists()){
                file.delete();
            }
            uploadFileService.updateStatus(url,"0");
            return "success";
        }catch (Exception e){
            return "fail";
        }
    }


}
